function goods(){
	class List{
	        constructor(){
	            this.url = "http://localhost/ClassProject/huinongwang/project/static/good-list.json";
	            this.cont1 = document.querySelector(".cont");
				// console.log(this.cont1)
	            this.load();
				this.addEvent();
	        }
	        load(){
	            ajax({
	                url:this.url
	            }).then((res)=>{
	                this.res = JSON.parse(res);
					// console.log(res);
	                this.display();
	            })
	        }
	        display(){
	            // console.log(this.res);
	            let str = "";
	            for(var i=0;i<this.res.length;i++){
	                str += `<a href="details.html?id=${this.res[i].goodsId}"><li index="${this.res[i].goodsId}">
					<img src="${this.res[i].img.largeImg[0]}" alt="">
					<div class="intro-li-x">
						<span><i>${this.res[i].price}</i>${this.res[i].each}</span>
						<em>${this.res[i].quality}</em>
					</div>
					<div class="intro-li-xx">
						<span><i>${this.res[i].choose}</i></span>
						<em>${this.res[i].describe}</em>
					</div>
					<div class="intro-li-xxx">
						<i>${this.res[i].hours}</i>
					</div>
					</a>
					<div class="intro-li-b login" index="${this.res[i].goodsId}">
						<input type="button" value="加入购物车" class="add">
					</div>
				</li>`
	            }
				// console.log(this.cont1)
	            this.cont1.innerHTML = str;
	        }
			
			addEvent(){
				var that = this;
				this.cont1.onclick = function(eve){
					var e = eve || window.event;
					var tar = e.target || e.srcElement;
					if(tar.className === "add"){
						// 点击的时候获取对应父元素节点的goodsId号
						that.goodsId = tar.parentNode.getAttribute("index");
						that.setData();
					}
				}
			}
			setData(){
				var gm = localStorage.getItem("goodsMsg")
<<<<<<< HEAD
				console.log(this.getData(this.goodsId))
=======
>>>>>>> 5d0a21b06dc39f26b412b2b946e3b19ba3adfcec
				if(gm === null){
					gm = [{
						goodsId:this.goodsId,
						num:1,
<<<<<<< HEAD
						msg:this.getData(this.goodsId)
=======
						msg:this.goodsId
>>>>>>> 5d0a21b06dc39f26b412b2b946e3b19ba3adfcec
					}];
				}else{
					gm = JSON.parse(gm)
					var zhuangtai = 0;
					for(var i = 0;i<gm.length;i++){
						// 1-2-1.有：数量+1
						if(gm[i].goodsId === this.goodsId){
							gm[i].num++;
							zhuangtai = 1;
							break;
						}
					}
					if(zhuangtai === 0){
						gm.push({
							goodsId:this.goodsId,
							num:1,
<<<<<<< HEAD
							msg:this.getData(this.goodsId)
=======
							msg:this.goodsId
>>>>>>> 5d0a21b06dc39f26b412b2b946e3b19ba3adfcec
						})
					}
				}
				localStorage.setItem("goodsMsg",JSON.stringify(gm))
			}
			getData(id){
<<<<<<< HEAD
				for(var i = 0;i<this.res.length;i++){
					if(this.res[i].goodsId === id){
						return this.res[i];
=======
				for(var i = 0;i<this.data.length;i++){
					if(this.data[i].goodsId === id){
						return this.data[i];
>>>>>>> 5d0a21b06dc39f26b412b2b946e3b19ba3adfcec
					}
				}
				return{};
			}

	    }
	new List();
}



function goods1(){
	class Index{
	        constructor(){
				this.resig = document.querySelector(".resig");
				this.Name = document.getElementById("user")

	            // 对于需要验证是否登录的页面来说，应该立即获取是否登录的信息
	            this.init();
	        }
	        init(){
	            // 获取之后，简单处理数据
	            this.m = sessionStorage.getItem("userMsg");
	            this.m = this.m ? JSON.parse(this.m) : {};
	            // 如果有登录成功后的信息
	            if(this.m.user){
	                // 显示登录的用户名
					this.Name.innerHTML = this.m.user;
					this.resig.style.display = "none";

	            }
	        }
	    }
	    new Index;

}
